package org.yu.team2023.flashdays;

import net.minecraft.world.entity.Attackable;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.player.Player;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;

public interface SetTiger {

     Map<String, SetTiger> SET_TIGER_MAP =new HashMap<>();

    static void register(String key, SetTiger tiger){
        SET_TIGER_MAP.put(key,tiger);
    }
    static SetTiger getOrDefault(String key){
        return SET_TIGER_MAP.getOrDefault(key,EMPTY);
    }

    void onFormedTwo(Player player);
    void onUnformedTwo(Player player);
    void onFormedFour(Player player);
    void onUnformedFour(Player player);
    SetTiger EMPTY=new SetTiger() {
        @Override
        public void onFormedTwo(Player player) {

        }

        @Override
        public void onUnformedTwo(Player player) {

        }

        @Override
        public void onFormedFour(Player player) {

        }

        @Override
        public void onUnformedFour(Player player) {

        }
    };
    static SetTiger byAttribute2(String name, Supplier<Attribute> attributeSupplier, double amount , AttributeModifier.Operation operation){
        UUID uuid=UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8));
        return new SetTiger() {
            @Override
            public void onFormedTwo(Player player) {
                if(player.getAttributes().hasAttribute(attributeSupplier.get())){
                    player.getAttribute(attributeSupplier.get()).addTransientModifier(new AttributeModifier(uuid,name,amount,operation));
                }
            }

            @Override
            public void onUnformedTwo(Player player) {
                if(player.getAttributes().hasAttribute(attributeSupplier.get())){
                    player.getAttribute(attributeSupplier.get()).removeModifier(uuid);
                }
            }

            @Override
            public void onFormedFour(Player player) {

            }

            @Override
            public void onUnformedFour(Player player) {

            }
        };
    }
}
